﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NBehave.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;
using MvcEngine.Core.Repositories;
using MvcEngine.Mvc.Controllers;
using MvcEngine.Core.Models.Entities;
using MvcEngine.Web.Tests.Fakes;
using MvcEngine.Mvc.Models.ViewModels;

namespace MvcEngine.Mvc.Scenarios
{
    [TestClass, Theme]
    public class LogControllerTestScenarios
    {
        private MockRepository mocks = new MockRepository();
        private ILogRepository repository;
        private LogController controller;

        [TestInitialize]
        public void Setup()
        {
            repository = mocks.StrictMock<ILogRepository>();
            controller = new LogController();
        }

        [TestMethod, Story]
        public void GetAllLogs()
        {
            List<ILog> logs = new List<ILog>() { new LogFake() };
            MvcEngineModelItem<LogViewData> data =null;

            Story story = new Story("GetAllLogs");
            story.AsA("Admin")
              .IWant("to get all logs from a data store")
              .SoThat("I can see all logs");

            story.WithScenario("GetAllLogs")
            .Given("Logs are retrieved from a data store via logrepository ", () => { Expect.Call(repository.GetAll()).Return(logs); mocks.ReplayAll(); })
            .When("the index action is executed", delegate { data = controller.Index(); }).
            Then("controller returns 1 log", () => { Assert.AreEqual(1, data.Item.Logs.Count); });

        }

    }
}
